import java.util.concurrent.atomic.AtomicInteger;

/**
 * Creat by TanLei
 * Description:
 * User:86183
 * Date:2022-06-16
 * Time:13:51
 */
public class Test2 {
    private static AtomicInteger num = new AtomicInteger(0);

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 50000; i++) {
                num.getAndIncrement();
            }
        });

        Thread t2 = new Thread(() -> {
            for (int i = 0; i < 50000; i++) {
                num.getAndIncrement();
            }
        });
        t1.start();
        t2.start();

        t1.join();
        t2.join();

        System.out.println(num.get());
//        AtomicInteger num = new AtomicInteger(0);
//        //这个操作相当于num++
//        num.getAndIncrement();
//        //这个操作相当与++num
//        num.incrementAndGet();
    }
}
